# -*- coding: utf-8 -*-
from django.db import models
from intraorg.slowniki.models import *

class Firma(models.Model):
    nazwa = models.CharField(maxlength=30)
    adres = models.TextField()
    miasto = models.ForeignKey(Miasto)
    kraj = models.ForeignKey(Kraj)
    nip = models.CharField(maxlength=30, blank=True)
    regon = models.CharField(maxlength=30, blank=True)
    www = models.URLField(verify_exists=False, blank=True)
    informacje = models.TextField(blank=True)
    class Meta:
        ordering = ['nazwa']
        unique_together = (("nazwa", "kraj"),)
        verbose_name = "Firma"
        verbose_name_plural = "Firmy"
    def __unicode__(self):
        return self.nazwa
    class Admin:
        list_display = ('nazwa', 'miasto', 'kraj', 'nip', 'regon')
        list_filter = ['kraj', 'miasto']
        search_fields = ['nazwa', 'informacje']

class NumerTelefonu(models.Model):
    RODZAJ_TELEFONU = (
        ('kom', 'komórkowy'),
        ('dom', 'domowy'),
        ('slu', 'praca'),
        ('rod', 'rodzina'),
    )
    numer = models.CharField(maxlength=20, core=True)
    rodzaj = models.CharField(maxlength=3, choices=RODZAJ_TELEFONU, core=True)
    uwagi = models.TextField(blank=True)
    firma = models.ForeignKey('Firma', edit_inline=models.TABULAR, num_in_admin=3)
    def __unicode__(self):
        return self.numer
    class Meta:
        ordering = ['numer', 'rodzaj']
        verbose_name = "Numer telefonu"
        verbose_name_plural = "Numery telefonów"  
    class Admin:
        list_display = ('numer', 'rodzaj', 'uwagi')
        list_filter = ['rodzaj']

class Email(models.Model):
    email = models.EmailField(core=True)
    adresat = models.CharField(maxlength=20, blank=True, verbose_name="Adresat")
    firma = models.ForeignKey('Firma', edit_inline=models.TABULAR, num_in_admin=3)
    def __unicode__(self):
        return self.email
    class Meta:
        ordering = ['email']
        verbose_name = "Email"
        verbose_name_plural = "Emaile"
    class Admin:
        list_display = ('email', 'firma', 'adresat')
        list_filter = ['firma']


